/*  This file is part of YATracker.
    YATracker is free software: you can redistribute it and/or modify it under the terms
of the GNU Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
    YATracker is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public License along with
YATracker. If not, see <http://www.gnu.org/licenses/>. */

#ifndef YATMAPFILE_H
#define YATMAPFILE_H

#include <QFile>


struct __attribute__ ((__packed__)) YatMapFileHeader
{
    char    prefix[4];
    quint32 indexOffset;
    quint16 indexItemSize;
    quint32 indexSizeInItems;
    quint32 dataOffset;
    quint32 dataSize;
    float   bounds[4];
    quint32 projection;
    quint16 zoom;
    quint32 tileminx;
    quint32 tileminy;
    quint32 tilemaxx;
    quint32 tilemaxy;
    char    unused[20];
};

struct __attribute__ ((__packed__)) YatMapIndexItem
{
    quint32 dataOffset;
    quint32 dataSize;
    quint16 itemType;
    float   bounds[4];
    quint16 zoom;
    quint32 tilex;
    quint32 tiley;
    char    unused[12];
};


class YatMapFile
{
public:
    YatMapFile();
    bool    open(const QString &fileName);
    void    close();
    bool    hasTile(quint32 x, quint32 y);
    void*   getTile(quint32 x, quint32 y, int *pdatasize);
    quint16 getZoom() const { return m_header.zoom; }

private:
    QFile   m_file;
    YatMapFileHeader m_header;
    YatMapIndexItem* m_index;
};

#endif // YATMAPFILE_H
